home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / CodeWarrior Lite / Metrowerks C⁄C++ Lite / Libraries / Runtime / Runtime PPC / Sources / catch.s < prev    next >
Encoding:
Text File  |  1995-04-06  |  3.1 KB  |  131 lines  |  [TEXT/MPCC]

  1. #    catch.s        -    C++ 'catch' support routines for Metrowerks C++ for PowerPC
  2. #
  3. #    Copyright © 1995 metrowerks inc.  All Rights Reserved.
  4. #
  5. #
  6. #    THEORY OF OPERATION
  7. #
  8. #    The runtime support routines __setup_catchregbuffer() and __catch_jump() support
  9. #    the C++ exception handling facilities.
  10. #
  11. #    __setup_catchregbuffer() captures the state of the program in a CatchRegBuffer
  12. #    data structure (similar to a jmp_buf) which has the following C definition:
  13. #
  14. #        typedef struct CatchRegBuffer {
  15. #            unsigned long    ldc;        //    0: (not used)
  16. #            unsigned long    PC;            //    4: (not used)
  17. #            unsigned long    CR;            //    8: saved CR
  18. #            unsigned long    SP;            // 12: saved SP
  19. #            unsigned long    RTOC;        // 16: saved RTOC
  20. #            unsigned long    GPRs[19];    // 20: saved r13-r31
  21. #            double            FPRs[18];    // 96: saved fp14-fp31
  22. #            double            FPSCR;        //240: saved FPSCR
  23. #        } *CatchRegBuffer;
  24. #
  25. #    __catch_jump() restores the state and transfers to an exception handler with the
  26. #    appropriate registers, stack, TOC, etc.
  27. #
  28. #    These routines are defined as follows:
  29. #
  30. #        void __setup_catchregbuffer(CatchRegBuffer *crp);
  31. #        void __catch_jump(CatchRegBuffer *crp,void *pc);
  32. #
  33. #
  34. #    BUILD INSTRUCTIONS
  35. #
  36. #    To assemble this file:
  37. #
  38. #        ppcasm catch.s -o catch.o
  39. #
  40. #    The object file catch.o can be added directly to any CodeWarrior™ project.
  41. #
  42.  
  43.         dialect    powerpc
  44.  
  45. #
  46. #    Public Data
  47. #
  48.         csect    __setup_catchregbuffer{DS}
  49.         export    __setup_catchregbuffer{DS}
  50.         dc.l    .__setup_catchregbuffer{PR}
  51.         dc.l    TOC{TC0}
  52.         
  53.         csect    __catch_jump{DS}
  54.         export    __catch_jump{DS}
  55.         dc.l    .__catch_jump{PR}
  56.         dc.l    TOC{TC0}
  57.  
  58. #
  59. #    TOC pointers
  60. #
  61.         toc
  62.  
  63.  
  64. #    __setup_catchregbuffer    -    save non-volatile registers
  65. #
  66. #    On entry R3 points to a CatchRegBuffer struct.
  67. #
  68.         csect    .__setup_catchregbuffer{PR}
  69.         export    .__setup_catchregbuffer{PR}
  70.         mfcr    r6
  71.         stw        SP,12(r3)        #    save SP
  72.         stw        RTOC,16(r3)        #    save RTOC
  73.         stw        r6,8(r3)        #    save CR
  74.         stmw    r13,20(r3)        #    save r13-r31
  75.         mffs    fp0
  76.         stfd    fp14,96(r3)        #    save fp14-fp31
  77.         stfd    fp15,104(r3)
  78.         stfd    fp16,112(r3)
  79.         stfd    fp17,120(r3)
  80.         stfd    fp18,128(r3)
  81.         stfd    fp19,136(r3)
  82.         stfd    fp20,144(r3)
  83.         stfd    fp21,152(r3)
  84.         stfd    fp22,160(r3)
  85.         stfd    fp23,168(r3)
  86.         stfd    fp24,176(r3)
  87.         stfd    fp25,184(r3)
  88.         stfd    fp26,192(r3)
  89.         stfd    fp27,200(r3)
  90.         stfd    fp28,208(r3)
  91.         stfd    fp29,216(r3)
  92.         stfd    fp30,224(r3)
  93.         stfd    fp31,232(r3)
  94.         stfd    fp0,240(r3)        #    save FPSCR
  95.         blr
  96.  
  97.  
  98. #    __catch_jump    -    restore non-volatile registers and jump to catch-block
  99. #
  100. #    On entry R3 points to a CatchRegBuffer struct and R4 contains the destination address.
  101. #
  102.         csect    .__catch_jump{PR}
  103.         export    .__catch_jump{PR}
  104.         lwz        r6,8(r3)
  105.         mtctr    r4                #    destination address
  106.         mtcrf    255,r6            #    restore CR
  107.         lwz        SP,12(r3)        #    restore SP
  108.         lwz        RTOC,16(r3)        #    restore RTOC
  109.         lmw        r13,20(r3)        #    restore r13-r31
  110.         lfd        fp14,96(r3)        #    restore fp14-fp31
  111.         lfd        fp15,104(r3)
  112.         lfd        fp16,112(r3)
  113.         lfd        fp17,120(r3)
  114.         lfd        fp18,128(r3)
  115.         lfd        fp19,136(r3)
  116.         lfd        fp20,144(r3)
  117.         lfd        fp21,152(r3)
  118.         lfd        fp22,160(r3)
  119.         lfd        fp23,168(r3)
  120.         lfd        fp24,176(r3)
  121.         lfd        fp25,184(r3)
  122.         lfd        fp26,192(r3)
  123.         lfd        fp27,200(r3)
  124.         lfd        fp28,208(r3)
  125.         lfd        fp29,216(r3)
  126.         lfd        fp30,224(r3)
  127.         lfd        fp0,240(r3)
  128.         lfd        fp31,232(r3)
  129.         mtfsf    255,fp0            #    restore FPSCR
  130.         bctr
  131.